package antsHelper

import (
	"github.com/panjf2000/ants"
	"sync"
)

var pool *ants.Pool
var poolOnce sync.Once
func NewPool(size int,options...ants.Option)  (*ants.Pool,error){
	if size==0{
		size=ants.DEFAULT_ANTS_POOL_SIZE
	}
	return ants.NewPool(size,options...)
}

func GetPoolInstance()  *ants.Pool{
	poolOnce.Do(func() {
		pool=defaultPool()
	})
	return pool
}

func Submit(fun func())  {
	GetPoolInstance().Submit(fun)
}

func defaultPool()  *ants.Pool{
	newPool, _ := NewPool(ants.DEFAULT_ANTS_POOL_SIZE)
	return newPool
}